<template>
	<view class="title-bar">
		<!-- 如果不是一级页面，显示返回按钮 -->
		<view v-if="isSubPage" class="back-btn" @click="goBack">
			<image src="/static/back.png" mode="aspectFill" class=""></image>
		</view>
		<text class="title">{{ title }}</text>
		<view v-if="isForum" class="postM" @click="goPost">
			<image src="/static/forum/more.png" mode="aspectFill"></image>
		</view>
	</view>
</template>

<script>
	export default {
		name: "titleBar",
		props: {
			// 接收标题文字
			title: {
				type: String,
				default: ''
			},
			// 判断是否为二级以上页面
			isSubPage: {
				type: Boolean,
				default: false
			},
			// 是否论坛
			isForum: {
				type: Boolean,
				default: false
			}
		},
		methods: {
			// 返回上一页的方法
			goBack() {
				uni.navigateBack({
					delta: 1
				});
			},
			goPost() {
				uni.redirectTo({
					url: '/pages/forum/postMsg'
				})
			}
		}
	}
</script>

<style scoped>
	.title-bar {
		display: flex;
		align-items: center;
		background-color: #F9CB43;
		height: 170rpx;
		padding: 0 20rpx;
		position: relative;
	}

	.back-btn {
		position: absolute;
		left: 20rpx;
		top: 60%;
		transform: translateY(-50%);
	}

	.postM {
		position: absolute;
		right: 20rpx;
		top: 62%;
		transform: translateY(-50%);
	}

	.back-btn image {
		width: 43rpx;
		height: 40rpx;
	}

	.postM image {
		width: 60rpx;
		height: 60rpx;
	}

	.title {
		font-size: 42rpx;
		font-weight: bold;
		width: 100%;
		text-align: center;
		margin-top: 25rpx;
	}
</style>